/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Microsoft Public License, please send an email to 
 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 * ***************************************************************************/


#include "stdafx.h"
#include <pgl/core/pgl.h>
#include <pgl/core/PGLPavePropPage.h>
#include <pgl/core/PGLRegion.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPGLPavePropPage property page

IMPLEMENT_DYNCREATE(CPGLPavePropPage, CPropertyPage)

CPGLPavePropPage::CPGLPavePropPage(CPGLPaveStPtr pPave) : CPropertyPage(CPGLPavePropPage::IDD)
{
	//{{AFX_DATA_INIT(CPGLPavePropPage)
	m_iBorderType = -1;
	m_dBorderSizeBottom = 0.0;
	m_dBorderSizeLeft = 0.0;
	m_dBorderSizeTop = 0.0;
	m_dBorderSizeRight = 0.0;
	//}}AFX_DATA_INIT
	m_pPave = pPave;
}

CPGLPavePropPage::~CPGLPavePropPage()
{
}

void CPGLPavePropPage::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPGLPavePropPage)
	DDX_Radio(pDX, IDC_PGL_BORDER_NONE, m_iBorderType);
	DDX_Text(pDX, IDC_PGL_BORDERSIZE_BOTTOM, m_dBorderSizeBottom);
	DDX_Text(pDX, IDC_PGL_BORDERSIZE_LEFT, m_dBorderSizeLeft);
	DDX_Text(pDX, IDC_PGL_BORDERSIZE_TOP, m_dBorderSizeTop);
	DDX_Text(pDX, IDC_PGL_BORDERSIZE_RIGHT, m_dBorderSizeRight);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPGLPavePropPage, CPropertyPage)
	//{{AFX_MSG_MAP(CPGLPavePropPage)
		// NOTE: the ClassWizard will add message map macros here
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPGLPavePropPage message handlers

BOOL CPGLPavePropPage::OnKillActive() 
{
	PGL_ASSERT_VALID(m_pPave);
	
	UpdateData(TRUE);

	m_pPave->SetBorderSize(CPGLRectD(m_dBorderSizeLeft,
		m_dBorderSizeBottom,
		m_dBorderSizeRight,
		m_dBorderSizeTop));
	
	CPGLPave::EPaveBorderType bt;
	switch(m_iBorderType)
	{
	case 0:
		bt=CPGLPave::BorderNone;
		break;
	case 1:
		bt=CPGLPave::BorderLine;
		break;
	case 2:
		bt=CPGLPave::BorderPlain;
		break;
	case 3:
		bt=CPGLPave::BorderLowerRightShadow;
		break;
	case 4:
		bt=CPGLPave::BorderUpperRightShadow;
		break;
	case 5:
		bt=CPGLPave::BorderUpperLeftShadow;
		break;
	case 6:
		bt=CPGLPave::BorderLowerLeftShadow;
		break;
	}

	m_pPave->SetBorderType(bt);

	return CPropertyPage::OnKillActive();
}

BOOL CPGLPavePropPage::OnSetActive() 
{
	PGL_ASSERT_VALID(m_pPave);
	
	CPGLRectD rBorder = m_pPave->GetBorderSize();
	m_dBorderSizeBottom = rBorder.bottom;
	m_dBorderSizeLeft = rBorder.left;
	m_dBorderSizeRight = rBorder.right;
	m_dBorderSizeTop = rBorder.top;

	switch (m_pPave->GetBorderType())
	{
	case CPGLPave::BorderNone:
		m_iBorderType=0;
		break;
	case CPGLPave::BorderLine:
		m_iBorderType=1;
		break;
	case CPGLPave::BorderPlain:
		m_iBorderType=2;
		break;
	case CPGLPave::BorderLowerRightShadow:
		m_iBorderType=3;
		break;
	case CPGLPave::BorderUpperRightShadow:
		m_iBorderType=4;
		break;
	case CPGLPave::BorderUpperLeftShadow:
		m_iBorderType=5;
		break;
	case CPGLPave::BorderLowerLeftShadow:
		m_iBorderType=6;
		break;
	}
	

	UpdateData(FALSE);

	return CPropertyPage::OnSetActive();
}
